<!DOCTYPE html>
<html>

  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  <title>用JitPack发布开源库时附加文档和源码</title>
  <meta name="description" content="使用JitPack发布开源库的同时添加上源码(sources) 和 文档注释(Javadoc)的 build.gradle 配置方法。">
  <meta name="author" content="GcsSloop">
  <meta name="keywords" content="Android, Jitpack,Javadoc, sources, GcsSloop">
  <meta name="关键字" content="Android, Jitpack,Javadoc, sources, GcsSloop">
  

  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="用JitPack发布开源库时附加文档和源码">
  <meta name="twitter:description" content="使用JitPack发布开源库的同时添加上源码(sources) 和 文档注释(Javadoc)的 build.gradle 配置方法。">
  <meta name="twitter:keywords" content="Android, Jitpack,Javadoc, sources, GcsSloop">
  
  <meta property="og:type" content="article">
  <meta property="og:title" content="用JitPack发布开源库时附加文档和源码">
  <meta property="og:description" content="使用JitPack发布开源库的同时添加上源码(sources) 和 文档注释(Javadoc)的 build.gradle 配置方法。">
  <meta name="og:keywords" content="Android, Jitpack,Javadoc, sources, GcsSloop">

  <meta name="theme-color" content="#343434">
  
  <link rel="icon" type="image/png" href="https://raw.githubusercontent.com/GcsSloop/gcssloop.github.io/master/assets/siteinfo/favicon.png" />
  <link href="https://raw.githubusercontent.com/GcsSloop/gcssloop.github.io/master/assets/siteinfo/favicon.png" rel="shortcut icon" type="image/png">
  
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/css/main.css">

  <link rel="canonical" href="http://www.gcssloop.com/course/jitpack-sources-javadoc">
  <link rel="alternate" type="application/rss+xml" title="GcsSloop" href="http://www.gcssloop.com/feed.xml">
  
  <meta name="google-site-verification" content="Z_g58PkzRAyBMxkqrcDdWrTBK8oOWM-7rUHauhLNF2E" />
  <meta name="baidu-site-verification" content="kUtTXCKaZs" />
  <meta name="baidu-site-verification" content="6DuDv3aaJX" />
  
  <!--阅读次数统计-->
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"> </script>
  
  <!--Fuck Weixin and Baidu-->
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv=”Cache-Control” content=”no-siteapp” />
  <meta name="applicable-device" content="pc,mobile">
  <meta name="HandheldFriendly" content="true"/>

  <!-- Google Ad -->
  <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  <script>
    (adsbygoogle = window.adsbygoogle || []).push({
      google_ad_client: "ca-pub-2767831356529421",
      enable_page_level_ads: true
    });
  </script>

</head>


  <body>

    <span class="mobile btn-mobile-menu">
        <i class="fa fa-list btn-mobile-menu__icon"></i>
        <i class="fa fa-angle-up btn-mobile-close__icon hidden"></i>
    </span>
    
    <header class="panel-cover panel-cover--collapsed" style="background-image: url('/assets/siteinfo/background-cover.jpg')">
  <div class="panel-main">

    <div class="panel-main__inner panel-inverted">
    <div class="panel-main__content">

        <a href="/#blog" title="前往 GcsSloop 的主页" class="blog-button"><img src="/assets/siteinfo/avatar.jpg" width="80" alt="GcsSloop logo" class="panel-cover__logo logo" /></a>
        <h1 class="panel-cover__title panel-title"><a href="/#blog" title="link to homepage for GcsSloop" class="blog-button">GcsSloop</a></h1>

        
        <span class="panel-cover__subtitle panel-subtitle">Just do IT later.</span>
        
        <hr class="panel-cover__divider" />
        <p class="panel-cover__description">嗨，我是 GcsSloop，一名来自2.5次元的魔法师，Android自定义View系列文章作者，非著名程序员。</p>
        <hr class="panel-cover__divider panel-cover__divider--secondary" />
        
        
        <p class="panel-cover__description">欢迎来到我的魔法世界!</p>
        
        
        <div class="navigation-wrapper">
          <div>
            <nav class="cover-navigation cover-navigation--primary">
              <ul class="navigation">
                <li class="navigation__item"><a href="/#blog" title="访问博客" class="blog-button">博客</a></li>
                
                  
                    <li class="navigation__item"><a href="https://github.com/GcsSloop" target="_blank" title="GcsSloop's GitHub">GitHub</a></li>
                  
                  
                
                  
                    <li class="navigation__item"><a href="/timeline" title="博客目录">目录</a></li>
                  
                  
                
                  
                    <li class="navigation__item"><a href="https://xiaozhuanlan.com/u/GcsSloop" target="_blank" title="小专栏">专栏</a></li>
                  
                  
                
                  
                    <li class="navigation__item"><a href="/category/customview" title="自定义View教程目录">自定义控件</a></li>
                  
                  
                
                  
                    <li class="navigation__item"><a href="/friends" title="友链">友链</a></li>
                  
                  
                
              </ul>
            </nav>
          </div>
          
          <div><nav class="cover-navigation navigation--social">
  <ul class="navigation">

  
  <!-- Weibo -->
  <li class="navigation__item">
    <a href="http://weibo.com/GcsSloop" title="@GcsSloop 的微博" target="_blank">
      <i class='social fa fa-weibo'></i>
      <span class="label">Weibo</span>
    </a>
  </li>
  

  
  <!-- Github -->
  <li class="navigation__item">
    <a href="https://github.com/GcsSloop" title="@GcsSloop 的 Github" target="_blank">
      <i class='social fa fa-github'></i>
      <span class="label">Github</span>
    </a>
  </li>
  
  
  
  <!-- Twitter -->
  <li class="navigation__item">
    <a href="http://twitter.com/GcsSloop" title="@GcsSloop" target="_blank">
      <i class='social fa fa-twitter'></i>
      <span class="label">Twitter</span>
    </a>
  </li>
  

    

  

  
  <!-- RSS -->
  <li class="navigation__item">
    <a href="/feed.xml" rel="author" title="RSS" target="_blank">
      <i class='social fa fa-rss'></i>
      <span class="label">RSS</span>
    </a>
  </li>
  

  
  <!-- Email -->
  <li class="navigation__item">
    <a href="mailto:GcsSloop@gmail.com" title="发邮件给我">
      <i class='social fa fa-envelope'></i>
      <span class="label">Email</span>
    </a>
  </li>
  

  
  <!-- Copyright -->
  <li class="navigation__item">
    <a href="http://choosealicense.online" title="选择版权"  target="_blank">
      <i class="social fa fa-copyright"></i>
      <span class="label">版权</span>
    </a>
  </li>
  
  
  </ul>
</nav>
</div>
        </div>
      </div>
    </div>
    
    
    <div class="panel-cover--overlay cover-slate"></div>
    
  </div>
</header>


    <div class="content-wrapper">
        <div class="content-wrapper__inner">
            <article class="post-container post-container--single" itemscope itemtype="http://schema.org/BlogPosting">
  <header class="post-header">
    <div class="post-meta" style="font-size:.8em">
      <time datetime="2016-09-09 00:00:00 +0800" itemprop="datePublished" class="post-meta__date date">2016-09-09</time> &#8226; <span class="post-meta__tags tags">Android,Jitpack</span> &#8226; View <span id="busuanzi_value_page_pv"></span> times.
</span>
    </div>
    <h1 class="post-title">用JitPack发布开源库时附加文档和源码</h1>
  </header>

  <section class="post">
    <p>很早之前写过一篇<a href="http://www.gcssloop.com/course/PublishLibraryByJitPack/">用JitPack发布Android开源库</a>的文章，有小伙伴反馈说<strong>发布到JitPack上的开源库没有文档注释，使用起来很不方便</strong>，这是我的失误，上一篇文章只是讲解了如何使用JitPack发布开源库，最终发布的只有arr(即编译好的动态链接库)，不仅没有文档注释(Javadoc)，也没有源码(sources)，本次就教大家如何在发布同时添加上注释和源码。</p>

<p><strong>由于JitPack本身就是一个自定义Maven仓库，所以与上传Maven的配置方式基本一样。</strong></p>

<h3 id="配置项目的-buildgradle">配置项目的 build.gradle</h3>

<p>项目的 build.gradle 配置和上一篇一样，没有变化。</p>

<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">buildscript</span> <span class="o">{</span> 
  <span class="n">dependencies</span> <span class="o">{</span>
    <span class="c1">// 重点就是下面这一行(上面两行是为了定位这一行的添加位置)</span>
    <span class="n">classpath</span> <span class="err">'</span><span class="n">com</span><span class="o">.</span><span class="na">github</span><span class="o">.</span><span class="na">dcendents</span><span class="o">:</span><span class="n">android</span><span class="o">-</span><span class="n">maven</span><span class="o">-</span><span class="n">gradle</span><span class="o">-</span><span class="nl">plugin:</span><span class="mf">1.3</span><span class="err">'</span> 
</code></pre>
</div>

<h3 id="配置-library-的-buildgradle">配置 Library 的 build.gradle</h3>

<p>完整示例(重点内容已经用注释标出):</p>

<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">apply</span> <span class="nl">plugin:</span> <span class="err">'</span><span class="n">com</span><span class="o">.</span><span class="na">android</span><span class="o">.</span><span class="na">library</span><span class="err">'</span>
<span class="n">apply</span> <span class="nl">plugin:</span> <span class="err">'</span><span class="n">com</span><span class="o">.</span><span class="na">github</span><span class="o">.</span><span class="na">dcendents</span><span class="o">.</span><span class="na">android</span><span class="o">-</span><span class="n">maven</span><span class="err">'</span> <span class="c1">// 添加这个</span>

<span class="n">group</span><span class="o">=</span><span class="err">'</span><span class="n">com</span><span class="o">.</span><span class="na">github</span><span class="o">.</span><span class="na">GcsSloop</span><span class="err">'</span>	<span class="c1">// 指定group，com.github.&lt;用户名&gt;</span>

<span class="n">android</span> <span class="o">{</span>
    <span class="n">compileSdkVersion</span> <span class="mi">23</span>
    <span class="n">buildToolsVersion</span> <span class="s">"23.0.3"</span>

    <span class="n">defaultConfig</span> <span class="o">{</span>
        <span class="n">minSdkVersion</span> <span class="mi">7</span>
        <span class="n">targetSdkVersion</span> <span class="mi">23</span>
        <span class="n">versionCode</span> <span class="mi">1</span>
        <span class="n">versionName</span> <span class="s">"1.0"</span>
    <span class="o">}</span>
    <span class="n">buildTypes</span> <span class="o">{</span>
        <span class="n">release</span> <span class="o">{</span>
            <span class="n">minifyEnabled</span> <span class="kc">false</span>
            <span class="n">proguardFiles</span> <span class="nf">getDefaultProguardFile</span><span class="o">(</span><span class="err">'</span><span class="n">proguard</span><span class="o">-</span><span class="n">android</span><span class="o">.</span><span class="na">txt</span><span class="err">'</span><span class="o">),</span> <span class="err">'</span><span class="n">proguard</span><span class="o">-</span><span class="n">rules</span><span class="o">.</span><span class="na">pro</span><span class="err">'</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="n">dependencies</span> <span class="o">{</span>
    <span class="n">compile</span> <span class="nf">fileTree</span><span class="o">(</span><span class="nl">dir:</span> <span class="err">'</span><span class="n">libs</span><span class="err">'</span><span class="o">,</span> <span class="nl">include:</span> <span class="o">[</span><span class="err">'</span><span class="o">*.</span><span class="na">jar</span><span class="err">'</span><span class="o">])</span>
    <span class="n">testCompile</span> <span class="err">'</span><span class="nl">junit:junit:</span><span class="mf">4.12</span><span class="err">'</span>
    <span class="n">compile</span> <span class="err">'</span><span class="n">com</span><span class="o">.</span><span class="na">android</span><span class="o">.</span><span class="na">support</span><span class="o">:</span><span class="n">appcompat</span><span class="o">-</span><span class="nl">v7:</span><span class="mf">23.4</span><span class="o">.</span><span class="mi">0</span><span class="err">'</span>
<span class="o">}</span>

<span class="c1">//---------------------------------------------</span>

<span class="c1">// 指定编码</span>
<span class="n">tasks</span><span class="o">.</span><span class="na">withType</span><span class="o">(</span><span class="n">JavaCompile</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">options</span><span class="o">.</span><span class="na">encoding</span> <span class="o">=</span> <span class="s">"UTF-8"</span>
<span class="o">}</span>

<span class="c1">// 打包源码</span>
<span class="n">task</span> <span class="nf">sourcesJar</span><span class="o">(</span><span class="nl">type:</span> <span class="n">Jar</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">from</span> <span class="n">android</span><span class="o">.</span><span class="na">sourceSets</span><span class="o">.</span><span class="na">main</span><span class="o">.</span><span class="na">java</span><span class="o">.</span><span class="na">srcDirs</span>
    <span class="n">classifier</span> <span class="o">=</span> <span class="err">'</span><span class="n">sources</span><span class="err">'</span>
<span class="o">}</span>

<span class="n">task</span> <span class="nf">javadoc</span><span class="o">(</span><span class="nl">type:</span> <span class="n">Javadoc</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">failOnError</span>  <span class="kc">false</span>
    <span class="n">source</span> <span class="o">=</span> <span class="n">android</span><span class="o">.</span><span class="na">sourceSets</span><span class="o">.</span><span class="na">main</span><span class="o">.</span><span class="na">java</span><span class="o">.</span><span class="na">sourceFiles</span>
    <span class="n">classpath</span> <span class="o">+=</span> <span class="n">project</span><span class="o">.</span><span class="na">files</span><span class="o">(</span><span class="n">android</span><span class="o">.</span><span class="na">getBootClasspath</span><span class="o">().</span><span class="na">join</span><span class="o">(</span><span class="n">File</span><span class="o">.</span><span class="na">pathSeparator</span><span class="o">))</span>
    <span class="n">classpath</span> <span class="o">+=</span> <span class="n">configurations</span><span class="o">.</span><span class="na">compile</span>
<span class="o">}</span>

<span class="c1">// 制作文档(Javadoc)</span>
<span class="n">task</span> <span class="nf">javadocJar</span><span class="o">(</span><span class="nl">type:</span> <span class="n">Jar</span><span class="o">,</span> <span class="nl">dependsOn:</span> <span class="n">javadoc</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">classifier</span> <span class="o">=</span> <span class="err">'</span><span class="n">javadoc</span><span class="err">'</span>
    <span class="n">from</span> <span class="n">javadoc</span><span class="o">.</span><span class="na">destinationDir</span>
<span class="o">}</span>

<span class="n">artifacts</span> <span class="o">{</span>
    <span class="n">archives</span> <span class="n">sourcesJar</span>
    <span class="n">archives</span> <span class="n">javadocJar</span>
<span class="o">}</span>
</code></pre>
</div>

<h3 id="发布参照上一篇文章-使用jitpack发布开源库">发布参照上一篇文章： <a href="http://www.gcssloop.com/course/PublishLibraryByJitPack/">使用JitPack发布开源库</a></h3>

<h3 id="查看在线文档">查看在线文档</h3>

<p>如果你在JitPack配置了文档和源码支持，在引用同时就包含了源码和文档，不仅如此，你也可以在线查看。</p>

<p>查看地址是: <code class="highlighter-rouge">https://jitpack.io/com/github/USER/REPO/VERSION/javadoc/</code></p>

<p>例如我的一个开源库：<code class="highlighter-rouge">https://jitpack.io/com/github/GcsSloop/ViewSupport/v1.2.2/javadoc/</code></p>

<p>在线API文档样式：
<img src="http://gcsblog.oss-cn-shanghai.aliyuncs.com/blog/2019-04-29-072339.jpg?gcssloop" alt="" /></p>

    <hr>
  </section>
</article>

<!--广告-->

<!--
<div>
<a href="https://m.aliyun.com/act/team1111/?spm=5176.11533457.1089570.5.424777e3AF8WOJ&userCode=hn5smxtw#/" target="_blank"><img src="/assets/aliyun/1111-980-120.jpg" width="100%"></a>
</div>
-->
<!--捐赠晶石-->
<section class="contribute">
    <script type="text/javascript"> 
      function toggle() {
        var con = document.getElementById("contribute");
        if (con.style.display == "none") {
          con.style.display = "block";
        } else {
          con.style.display = "none";
        }
      }
    </script> 
    <blockquote style="background-color:#F5F5F5; padding: 10px 20px 20px 10px; margin:0px" >
      <h4> 如果你觉得我的文章对你有帮助的话，欢迎赞助一些服务器费用! </h4>
      <p></p>
      <a id=“btn-toggle-contribute” class="btn-contribute" onclick="toggle()" >¥ 点击赞助</a>
      <br>
      <div id="contribute" style="display:none;">
        <p align="center" >
        <img src="/assets/images/wechat.png" alt="微信">
        <img src="/assets/images/alipay.png" alt="支付宝">
        </p>
        <p align="left" >
          <b>感谢所有支持我的魔法师，所有支持过我的魔法师都可以通过微信(GcsSloop)联系我，获赠我的付费专栏！</b>
          <!--
          <a href="/contribute">点击这里查看捐赠者名单。</a>
          -->
        </p>
      </div>
    </blockquote>
</section>
<div>
  <h2>欢迎关注我的微信公众号</h2>
  <img src="/assets/images/banner.jpg" width="100%">
</div>

<!--阅读更多-->
<section class="read-more">
  
  
  <div class="read-more-item">
    <span class="read-more-item-dim">最近的文章</span>
    <h2 class="post-list__post-title post-title"><a href="/customview/matrix-3d-camera" title="link to 安卓自定义View进阶-Matrix Camera">安卓自定义View进阶-Matrix Camera</a></h2>
    <p class="excerpt">本篇依旧属于Matrix，主要讲解Camera，Android下有很多相机应用，其中的美颜相机更是不少，不过今天这个Camera可不是我们平时拍照的那个相机，而是graphic包下的Camera...&hellip;</p>
    <div class="post-list__meta">
      <time datetime="2016-09-14 00:00:00 +0800" class="post-list__meta--date date">2016-09-14</time> &#8226; <span class="post-list__meta--tags tags">CustomView</span>
      <br/><br/>
      <a style="float:none; margin:0 auto;" class="btn-border-small" href=/customview/matrix-3d-camera>继续阅读</a></div>
   </div>
   
   
   
   
   <div class="read-more-item">
       <span class="read-more-item-dim">更早的文章</span>
       <h2 class="post-list__post-title post-title"><a href="/customview/Matrix_Method" title="link to 安卓自定义View进阶-Matrix详解">安卓自定义View进阶-Matrix详解</a></h2>
       <p class="excerpt">这应该是目前最详细的一篇讲解Matrix的中文文章了，在上一篇文章Matrix原理中，我们对Matrix做了一个简单的了解，偏向理论，在本文中则会详细的讲解Matrix的具体用法，以及与Matr...&hellip;</p>
       <div class="post-list__meta">
          <time datetime="2016-08-30 00:00:00 +0800" class="post-list__meta--date date">2016-08-30</time> &#8226; <span class="post-list__meta--tags tags">CustomView</span>
          <br/><br/>
          <a style="float:none; margin:0 auto;" class="btn-border-small" href=/customview/Matrix_Method>继续阅读</a>
       </div>
   </div>
   
</section>

<!--网易云跟帖-->
<!--
<div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
<script src="https://img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"></script>
<script>
var cloudTieConfig = {
  url: document.location.href, 
  sourceId: "",
  productKey: "a85dba2840134721a7b69a15b2e0f217",
  target: "cloud-tie-wrapper"
};
var yunManualLoad = true;
Tie.loader("aHR0cHM6Ly9hcGkuZ2VudGllLjE2My5jb20vcGMvbGl2ZXNjcmlwdC5odG1s", true);
</script>
-->

<style type="text/css">
.isso-comment > div.avatar {
    border: 0px;
    box-shadow: none;
    display: block;
    float: left;
    width: 7%;
    margin: 3px 15px 0 0;
}
.isso-postbox > .form-wrapper > .auth-section .post-action > input {
    border-radius: 6px;
    padding: 6px;
    padding-left: 16px;
    padding-right: 16px;
    border: 1px solid #CCC;
    background-color: #D58D44;
    cursor: pointer;
    outline: 0;
    color: #fff;
    size: 10;
    line-height: 1.4em;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.isso-postbox > .form-wrapper > .auth-section .post-action > input:hover {
    background-color: #272822;
}
.isso-postbox > .form-wrapper > .auth-section .post-action > input:active {
    background-color: #986530;
}
</style>

<section id="isso-thread"></section>

<script data-isso="//47.52.58.34:1234/"
        data-isso-css="true"
        data-isso-lang="zh"
        data-isso-reply-to-self="false"
        data-isso-require-author="false"
        data-isso-require-email="false"
        data-isso-max-comments-top="10"
        data-isso-max-comments-nested="5"
        data-isso-reveal-on-click="5"
        data-isso-avatar="true"
        data-isso-avatar-bg="#f0f0f0"
        data-isso-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..."
        data-isso-vote="true"
        data-vote-levels=""
        src="//47.52.58.34:1234/js/embed.min.js">
        </script>

<!--
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
-->
<!-- OneV's Den -->
<!--
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-3324997515191619"
     data-ad-slot="9170309685"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
-->

            <section class="footer">
    <footer>
    	<span class="footer__copyright">本站点采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" target="_blank">知识共享 署名-非商业性使用-禁止演绎 4.0 国际 许可协议</a></span>
        <span class="footer__copyright">本站由 <a href="http://www.GcsSloop.com">@GcsSloop</a> 创建，采用 <a href="https://github.com/GcsSloop/Gcs-Vno-Jekyll" target="_blank">Gcs-Vno-Jekyll</a> 作为主题。<span id="busuanzi_container_site_pv"> 总访问量 <span id="busuanzi_value_site_pv"></span> 次</span> - &copy; 2019</span>
        <span class="footer__sitemap, footer__copyright"><a href="http://www.gcssloop.com/sitemap.xml" target="_blank">Site Map</a>
        <a href="http://www.gcssloop.com/vip" target="_blank">vip</a></span>
    </footer>
</section>

        </div>
    </div>
    
    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<script type="text/javascript" src="/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<script type="text/javascript" src="/js/main.js"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-82493667-1', 'auto');
  ga('send', 'pageview');

</script>

    
  </body>

</html>
